package library;

import java.util.HashMap;

import util.ConfigurationHelper;
import dom.EducationalSystemEnum;

public class LibraryProperties {

	private static HashMap<EducationalSystemEnum,Integer> UDPPorts = new HashMap<EducationalSystemEnum,Integer>();
	private static HashMap<EducationalSystemEnum,String> UDPHosts = new HashMap<EducationalSystemEnum,String>();
	private static HashMap<String,Integer> replicaPortData = new HashMap<String,Integer>();
	private static HashMap<String,String> replicaHostData = new HashMap<String,String>();
	
	private static final String UDP_PORT = "udp.port";
	private static final String UDP_HOST = "host.name";
	private static final String REPLICA_HOST = "replica.host";
	private static final String REPLICA_PORT = "replica.port";
	
	private static final String REPLICA_ONE_ID = "r1";
	private static final String REPLICA_TWO_ID = "r2";
	private static final String REPLICA_THREE_ID = "r3";
	private static final String REPLICA_FOUR_ID = "r4";
	
	static{
		// udp.port
		UDPPorts.put(EducationalSystemEnum.CONCORDIA,ConfigurationHelper.getIntProperty(UDP_PORT,EducationalSystemEnum.CONCORDIA.toString().toLowerCase()));
		UDPPorts.put(EducationalSystemEnum.MCGILL,ConfigurationHelper.getIntProperty(UDP_PORT,EducationalSystemEnum.MCGILL.toString().toLowerCase()));
		UDPPorts.put(EducationalSystemEnum.UQAM,ConfigurationHelper.getIntProperty(UDP_PORT,EducationalSystemEnum.UQAM.toString().toLowerCase()));
		// host.name
		UDPHosts.put(EducationalSystemEnum.CONCORDIA,ConfigurationHelper.getProperty(UDP_HOST,EducationalSystemEnum.CONCORDIA.toString().toLowerCase()));
		UDPHosts.put(EducationalSystemEnum.MCGILL,ConfigurationHelper.getProperty(UDP_HOST,EducationalSystemEnum.MCGILL.toString().toLowerCase()));
		UDPHosts.put(EducationalSystemEnum.UQAM,ConfigurationHelper.getProperty(UDP_HOST,EducationalSystemEnum.UQAM.toString().toLowerCase()));
		// replica host info
		replicaHostData.put(REPLICA_ONE_ID,ConfigurationHelper.getProperty(REPLICA_HOST, REPLICA_ONE_ID));
		replicaHostData.put(REPLICA_TWO_ID,ConfigurationHelper.getProperty(REPLICA_HOST, REPLICA_TWO_ID));
		replicaHostData.put(REPLICA_THREE_ID,ConfigurationHelper.getProperty(REPLICA_HOST, REPLICA_THREE_ID));
		replicaHostData.put(REPLICA_FOUR_ID,ConfigurationHelper.getProperty(REPLICA_HOST, REPLICA_FOUR_ID));
		// replica port info
		replicaPortData.put(REPLICA_ONE_ID,ConfigurationHelper.getIntProperty(REPLICA_PORT, REPLICA_ONE_ID));
		replicaPortData.put(REPLICA_TWO_ID,ConfigurationHelper.getIntProperty(REPLICA_PORT, REPLICA_TWO_ID));
		replicaPortData.put(REPLICA_THREE_ID,ConfigurationHelper.getIntProperty(REPLICA_PORT, REPLICA_THREE_ID));
		replicaPortData.put(REPLICA_FOUR_ID,ConfigurationHelper.getIntProperty(REPLICA_PORT, REPLICA_FOUR_ID));
	}

	public static HashMap<EducationalSystemEnum, Integer> getUDPPorts() {
		return UDPPorts;
	}

	public static HashMap<EducationalSystemEnum, String> getUDPHosts() {
		return UDPHosts;
	}

	public static int getPortById(EducationalSystemEnum key){
		int port = -1;
		if(UDPPorts.get(key) != null){
			port = UDPPorts.get(key);
		}
		return port;
	}
	
	public static int getPortById(String key){
		return getPortById(EducationalSystemEnum.valueOf(key.toUpperCase()));
	}
	
	public static String getHostnameById(EducationalSystemEnum key){
		String host = "";
		if(UDPPorts.get(key) != null){
			host = UDPHosts.get(key);
		}
		return host;
	}
	
	public static String getHostnameById(String key){
		return getHostnameById(EducationalSystemEnum.valueOf(key.toUpperCase()));
	}

	public static HashMap<String, Integer> getReplicaPortData() {
		return replicaPortData;
	}

	public static HashMap<String, String> getReplicaHostData() {
		return replicaHostData;
	}
	
	
}
